import React, {useState, useEffect} from "react";
import axios from "axios";

export default function NowPlaying(props) {
    const [list, setList] = useState([])

    useEffect(() => {
        axios({
            url: 'https://m.maizuo.com/gateway?cityId=110100&pageNum=1&pageSize=10&type=1&k=6408902',
            headers: {
                'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.1","e":"17594933621256179149832193"}',
                'X-Host': 'mall.film-ticket.film.list'
            }
        }).then(res => {
            setList(res.data.data.films);
        })
    }, [])

    function queryDetail(id) {
        // 编程式路由 跳转到详情页  props是父组件传过来的  这里的父组件是Route 不是Film
        props.history.push(`/detail/${id}`);
    }

    return <div>
        <ul>
            {list.map(item => <li onClick={() => queryDetail(item.filmId)} key={item.filmId}>{item.name}</li>)}
        </ul>
    </div>
}